<?php
namespace Admin\Controller;
class AdminController extends BaseController{
	/*管理员列表*/
	function admin_list(){
		$adminob=M('admin');
		$adminStr=$adminob->select();
		$adminnum=$adminob->count();
		$this->assign('adminStr',$adminStr);
		$this->assign('adminnum',$adminnum);
		$this->display();
	}
	function admin_add(){
		$this->display();
	}
	/*管理员添加*/
	function admin_add1(){
		$mOb=M('admin');
		unset($_POST['password2']);
		$re= $mOb->data($_POST)->add();
		if($re){
               /* $this->success('添加成功',U('Admin/Admin/admin_list'));*/
               echo "<script>alert('添加成功');parent.location.href='admin_list'</script>";
            }else{
                $this->error('添加失败',U('Admin/Admin/admin_add'));
            }
		$this->display();
	}
	/*删除*/
	function admin_del(){
		$id=$_GET['id'];
		$mOb=M('admin');
		$re=$mOb->where("id=$id")->delete();
		if($re){
               $this->success('删除成功',U('Admin/Admin/admin_list'));
               
            }else{
                $this->error('删除失败',U('Admin/Admin/admin_list'));
            }
		$this->display();
	}
	/*角色管理*/
	function admin_role(){

		  $mOb=M('admin_group');
		  $adminOb=M('admin');
		  $groupArr=$mOb->select();/*获得所有权限的分组名*/
		  $adminArr=$adminOb->select();/*获得不同权限组下的用户名*/
		  $this->assign('groupArr',$groupArr);
		  $this->assign('adminArr',$adminArr);
          $this->display();
	}
	/*角色添加*/
	function admin_role_add(){
		$mOb=M('admin_rule');
		$ruleArr=$mOb->select();
		$this->assign('ruleArr',$ruleArr);
		$this->display();
	}
	function admin_group(){
		$mOb=M('admin_group');

		print_r($_POST);
		exit();
        $re=$mOb->data($_POST)->add();

        if($re){
             echo 1;  
        }else{
        	echo 2;
        }
		$this->display();
	}
	function admin_permission_del(){             /*==========节点删除*/
       /* $id=$_GET['id'];
        $mOb=M('admin_rule');
        $re=$mOb->where("id=$id")->delete();
        if($re){
               echo 1;          
            } */
		$this->display();
	}
	
	/*权限管理*/
	function admin_permission(){
		$mOb=M('admin_rule');
		$ruleArr= $mOb->select();/*查询所有组名*/
		$this->assign('ruleArr',$ruleArr);
		$this->display();
	}
}